//
//  CLPagerController.h
//  Charles
//
//  Created by Leo on 2019/4/25.
//  Copyright © 2019 charles. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "CLPagerViewLayout.h"

NS_ASSUME_NONNULL_BEGIN

@class CLPagerController;
@protocol CLPagerControllerDataSource  <NSObject>

- (NSInteger)numberOfControllersInPagerController;
- (UIViewController *)pagerController:(CLPagerController *)pagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching;

@end

@protocol CLPagerControllerDelegate <NSObject>

- (void)pagerController:(CLPagerController *)pagerController viewWillAppear:(UIViewController *)viewController forIndex:(NSInteger)index;
- (void)pagerController:(CLPagerController *)pagerController viewDidAppear:(UIViewController *)viewController forIndex:(NSInteger)index;

- (void)pagerController:(CLPagerController *)pagerController viewWillDisappear:(UIViewController *)viewController forIndex:(NSInteger)index;
- (void)pagerController:(CLPagerController *)pagerController viewDidDisappear:(UIViewController *)viewController forIndex:(NSInteger)index;

- (void)pagerController:(CLPagerController *)pagerController transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex animated:(BOOL)animated;
- (void)pagerController:(CLPagerController *)pagerController transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress;

- (void)pagerControllerDidScroll:(CLPagerController *)pagerController;
- (void)pagerControllerWillBeginScrolling:(CLPagerController *)pagerController animate:(BOOL)animate;
- (void)pagerControllerDidEndScrolling:(CLPagerController *)pagerController animate:(BOOL)animate;

@end

@interface CLPagerController : UIViewController

@property (nonatomic, weak, nullable) id<CLPagerControllerDataSource> dataSource;
@property (nonatomic, weak, nullable) id<CLPagerControllerDelegate> delegate;
@property (nonatomic, strong, readonly) CLPagerViewLayout<UIViewController *> *layout;
@property (nonatomic, weak, readonly) UIScrollView *scrollView;

@property (nonatomic, assign, readonly) NSInteger countOfControllers;
@property (nonatomic, assign, readonly) NSInteger curIndex;

@property (nonatomic, strong, nullable, readonly) NSArray<UIViewController *> *visibleControllers;
@property (nonatomic, assign) BOOL automaticallySystemManagerViewAppearanceMethods;
@property (nonatomic, assign) UIEdgeInsets contentInset;

- (UIViewController *)controllerForIndex:(NSInteger)index;
- (void)registerClass:(Class)Class forControllerWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forControllerWithReuseIdentifier:(NSString *)identifier;
- (UIViewController *)dequeueReusableControllerWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;

- (void)scrollToControllerAtIndex:(NSInteger)index animate:(BOOL)animate;

- (void)updateData;

- (void)reloadData;

@end

NS_ASSUME_NONNULL_END
